package tech.aistar.corejava.day10.myexception;

/**
 * Created by 李雨昂 on 2019/7/20.
 */
public class Account {
    private int accNo;
    private String accName;
    private int accPassword;
    private String accTelno;
    private double accBalance;
    private int accType;


    public Account(int accNo, String accName, int accPassword, String accTelno, double accBalance, int accType) {
        this.accNo = accNo;
        this.accName = accName;
        this.accPassword = accPassword;
        this.accTelno = accTelno;
        this.accBalance = accBalance;
        this.accType = accType;

    }

    public Account() {

    }

    public int getAccNo() {
        return accNo;
    }

    public void setAccNo(int accNo) {
        this.accNo = accNo;
    }

    public String getAccName() {
        return accName;
    }

    public void setAccName(String accName) {
        this.accName = accName;
    }

    public int getAccPassword() {
        return accPassword;
    }

    public void setAccPassword(int accPassword) {
        this.accPassword = accPassword;
    }

    public String getAccTelno() {
        return accTelno;
    }

    public void setAccTelno(String accTelno) {
        this.accTelno = accTelno;
    }

    public double getAccBalance() {
        return accBalance;
    }

    public void setAccBalance(double accBalance) {
        this.accBalance = accBalance;
    }

    public int getAccType() {
        return accType;
    }

    public void setAccType(int accType) {
        this.accType = accType;
    }


    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Account{");
        sb.append("accNo=").append(accNo);
        sb.append(", accName='").append(accName).append('\'');
        sb.append(", accPassword=").append(accPassword);
        sb.append(", accTelno='").append(accTelno).append('\'');
        sb.append(", accBalance=").append(accBalance);
        sb.append(", accType=").append(accType);
        sb.append('}');
        return sb.toString();
    }

    //业务类和实体类合二为一的方式
    //业务方法仍然是在实体类中
    public void depoist(double money){
        if(money<=0){
            System.out.println("sorry,必须要存入有效金额!");
            return;
        }
        this.accBalance+=money;
    }

    public void withdraw(double money) throws BalanceNotException {
        if(money<=0 || money>this.accBalance){

            //抛出一个自定义的异常
            throw new BalanceNotException("余额不足!");
        }
        this.accBalance-=money;
    }


}
